/*
 * Copyright (c) 2014 Steve Tracey
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.stevetracey.backup.Backup;
import com.stevetracey.backup.BackupJobContext;
import com.stevetracey.backup.io.google.Google;
import com.stevetracey.common.Configuration;

public class RunBackup
{

	private static Log log = LogFactory.getLog(RunBackup.class);


	/**
	 * 
	 * Main Entry point for the program
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {

		Google.initialise();

		
		//loop through configuration and start a backup for each entry
		int counter = 1;

		Backup backup = new Backup();
		
		while (Configuration.getValue("backup." + counter + ".local.folder") != null)
		{
			
			String source = Configuration.getValue("backup." + counter + ".local.folder");
			String target = Configuration.getValue("backup." + counter + ".remote.folder");
			
			BackupJobContext backupConf = new BackupJobContext(source, target);
			
			log.info("Starting backup for [" + source + "] to " + "[" + target + "]");
			
			//initial manual sync
			
			backup.startBackup(backupConf);
			
			counter++;
			
		}
	}
}
